//
//  ZLTabViewController.m
//  LittleFairyPoet
//
//  Created by rimi on 15/9/8.
//  Copyright (c) 2015年 周林. All rights reserved.
//

#import "ZLTabViewController.h"
#import "SettingViewController.h"
#import "ZLScheduleViewController.h"
#import "ZLAnotationViewController.h"
#import "ZLGameViewController.h"
#import "DirectoryViewController.h"
#import "CollectionViewController.h"
#import "ZLDetailPoemViewController.h"


@interface ZLTabViewController ()
@property (nonatomic, strong) NSArray * titles;
@property (nonatomic, strong) NSArray * controllers;
- (void)initializeDataSource; /**< 初始化数据源 */
- (void)initializeUserInterface; /**< 初始化用户界面 */
@end

@implementation ZLTabViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initializeDataSource];
    [self initializeUserInterface];
}

#pragma mark - private
- (void)initializeDataSource {
    
}
- (void)initializeUserInterface {
    self.view.backgroundColor = [UIColor whiteColor];
    [self.navigationController setNavigationBarHidden:YES];
    self.leftButton.hidden = YES;
    for (int i = 0; i < self.titles.count; i++) {
        [self congfigButtonWithTitle:_titles[i] andWithTag:100+i andWithCenter:CGPointMake(160, 100+i*40)];
    }
}

- (void)congfigButtonWithTitle:(NSString *)title andWithTag:(NSInteger)tag andWithCenter:(CGPoint)center{
    UIButton * button = [UIButton buttonWithType:UIButtonTypeSystem];
    button.bounds = DHFlexibleFrame(CGRectMake(0, 0, 60, 30), YES);
    button.center = DHFlexibleCenter(center);
    button.tag = tag;
    [button setTitle:title forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont boldSystemFontOfSize:24];
    [button addTarget:self action:@selector(respondsToButton:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
}

#pragma mark - responds events
- (void)respondsToButton:(UIButton *)sender {
    Class class = NSClassFromString(self.controllers[sender.tag-100]);
    UIViewController * VC = [[class alloc]init];
    [self.navigationController pushViewController:VC animated:YES];
}

#pragma mark - getter
- (NSArray *)titles {
    if (!_titles) {
        _titles = @[@"游戏", @"学习", @"计划", @"收藏", @"设置", @"使用说明"];
    }
    return _titles;
}
- (NSArray *)controllers {
    if (!_controllers) {
        _controllers = @[@"ZLGameViewController",
                         @"DirectoryViewController",
                         @"ZLScheduleViewController",
                         @"CollectionViewController",
                         @"SettingViewController",
                         @"WPGuideViewController"];
    }
    return _controllers;
}
@end
